import request from './request';
import type {  LoginCredentials, RegisterData ,UserProfile } from '@/types/user';
import adminRequest, { baseURL } from './adminRequest';

// 用户注册
export const register = (data: RegisterData) => {  
  return request({
    url: '/auth/register',
    method: 'post',
    data 
  });
};
/**
 * 登录函数
 * @param data 登录凭据对象，包含用户名和密码等信息
 * @returns 返回一个请求对象，用于处理登录请求的响应
 */
export const login = (data: LoginCredentials) => {    
  return request({
    url: '/auth/login',
    method: 'post',
    data 
  });
};


// 退出登录
// export const logout = (data) => {   
//    return request({
//     url: '/auth/logout',
//     method: 'post',
//     data 
//   })
// }

// 获取当前用户信息
export const getUserInfo = () => {   
  return request({
    url: '/auth/me',
    method: 'get',
    params:  {} 
  });
};
// 更新当前用户信息
export const profileUserInfo = (data:UserProfile) => {   
  return request({
    url: '/users/profile',
    method: 'put',
    data 
  });
};

// 用户签到
export const userSignin = () => {   
  return request({
    url: '/signin/checkin',
    method: 'post'
     
  });
};
// 用户签到记录
export const userSigninStatus = (data:any) => {   
  return request({
    url: '/signin/status',
    method: 'get',
    params:  data
  });
};

/**
 * 管理员登录
 */
export const adminLogin = (data: LoginCredentials) => {
  return adminRequest({
    url: `${baseURL}/auth/login`,
    method: 'post',
    data
  });
};